package com.firefly.web.controller.home.test;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: thymeleaf 模板基础使用方法
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/11/19
 **/
@RestController
// 名字后面是时间，单位秒
@CacheConfig(cacheNames = "cacheTest#120")
public class CacheController {
    @GetMapping("cache/add")
    @CachePut(key = "'id_' + #id")
    public Map add(int id){
        Map result = new HashMap<>();
        result.put("id","sss");
        return result;
    }

    @GetMapping("cache/get")
    @Cacheable(key = "'id_' + #id")
    public Map get(int id){
        Map result = new HashMap<>();
        result.put("id","sss");
        return result;
    }
}
